﻿#pragma once

#include "type_cpp14.h"
namespace Support {
	using tUs = long long int;
	tUs getTimesUs();
	void msSleep(int ms);
	void setPriority(void);	
	enum class eTerminalColor {
		normal, highlight, warning, error
	};
	void setTerminalColor(eTerminalColor color);
	int getProcessName(char* ptr, int length);
	int getIncrementMs(tUs& base_time);

	class dErrorDelegate {
	public:
		static const int SOVED = 0;
		static const int CRASH = 1;
		static const int FROM_LOW = 2;
		virtual void __stdcall handle(int error_type, const char* format, ...) {}
	};
	class ErrorReportPrintf final :public dErrorDelegate {
	public:
		void __stdcall handle(int error_type, const char* format, ...) override;
	};
	extern ErrorReportPrintf error_reporter_printf_delegate;
	int usTotimestr(char* out_str, int len, tUs us_time);
};

namespace Support {
	inline bool _setTerminalColor(eTerminalColor color, bool first) {
		if (first) {
			setTerminalColor(color);
			return true;
		}
		else {
			setTerminalColor(eTerminalColor::normal);
			return false;
		}
	}
#define TERMINAL_COLOR(color) for(bool _TERMINAL_COLOR_STATUS = true;\
	Support::_setTerminalColor(color,_TERMINAL_COLOR_STATUS);\
	 _TERMINAL_COLOR_STATUS = false)

};